package com.codeboy.mediasoupandroiddemo;


import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.webrtc.SurfaceViewRenderer;

import java.util.List;

public class VideoRoomAdapter extends RecyclerView.Adapter<VideoRoomAdapter.ViewHolder> {
    private List<RendererData> mList;

    public VideoRoomAdapter(List<RendererData> list) {
        mList = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.adapter_video_room_item, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.mItem.removeAllViews();
        holder.mItem.addView(mList.get(position).viewRenderer);
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mItem;

        public ViewHolder(View view) {
            super(view);
            mItem = view.findViewById(R.id.ll_item);
        }
    }
}
